package nancal.mp.mvc.ops

import nancal.mp.service.K8sDeploymentService
import nbcp.base.annotation.*
import nbcp.base.comm.ListResult
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/ops/k8s/pod")
@RestController
class K8sPodController {

    @Autowired
    lateinit var k8sDeploymentService: K8sDeploymentService

    @RequestMapping("/list", method = arrayOf(RequestMethod.POST, RequestMethod.GET))
    fun list(targetEnv: String, @Require namespace: String, @Require serviceName: String): ListResult<String> {
        k8sDeploymentService.getPodList(targetEnv, namespace, serviceName)
            .apply {
                return ListResult.of(this)
            }
    }

    @Autowired
    lateinit var k8sService: K8sDeploymentService;

//
//    @PostMapping("/deploy2")
//    fun deploywww(name: String): String {
//        var appApi = AppsV1Api();
//        var deploymentResult = appApi.readNamespacedDeploymentStatus(name, "default", "true")
//        if (deploymentResult == null) return "null"
//
//        return deploymentResult.toString();
//    }

//    @GetMapping("/status/{namespace}/{name}/{version}")
//    fun getStatus(namespace: String, name: String, version: String, response: HttpServletResponse) {
//        var ret = k8sService.getStatus(namespace, name, version)
//        if (ret.code != 0) {
//            response.status = 500;
//            return;
//        }
//        return;
//    }
}